﻿/**************************************************************************************************************
 * Class name:  T_System_IO_Path.cs
 * Description: System.IO.Path 用法展示
 * Author:      Ju2ender
 * Create:      2012-12-04 Tuesday 14:40:45
 * Update:      2012-12-04 Tuesday 14:40:45
 **************************************************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace Web {

  public partial class T_System_IO_Path : System.Web.UI.Page {

    protected void Page_Load(object sender, EventArgs e) {
      
      if (!IsPostBack) {

        string visualPath, physicalPath,
               directoryName, fileName,
               fileNameWithoutExtension, extension,
               randomFileName;

        visualPath = Request.Path;
        Response.Write("当前请求的虚拟路径：<br />" + visualPath + "<br /><br />");

        physicalPath = Server.MapPath(visualPath);
        Response.Write("当前请求的物理路径：<br />" + physicalPath + "<br /><br />");

        directoryName = Path.GetDirectoryName(physicalPath);
        Response.Write("当前请求的目录物理路径：<br />" + directoryName + "<br /><br />");

        fileName = Path.GetFileName(visualPath);
        Response.Write("当前请求的文件名：<br />" + fileName + "<br /><br />");

        fileNameWithoutExtension = Path.GetFileNameWithoutExtension(visualPath);
        Response.Write("当前请求的文件名（不带扩展名）：<br />" + fileNameWithoutExtension + "<br /><br />");

        extension = Path.GetExtension(visualPath);
        Response.Write("当前请求的文件扩展名：<br />" + extension + "<br /><br />");

        randomFileName = Path.GetRandomFileName();
        Response.Write("随机文件夹名或文件名：<br />" + randomFileName + "<br /><br />");

        Response.End();
      }
    }
  }
}